package com.pokermind.dse.tcp.client.preset;

import com.pokermind.common.util.CardCodec;
import com.pokermind.common.util.TablePositionConfig;
import com.pokermind.common.util.TablePositionConfig.PositionCategory;

import java.util.Arrays;
import java.util.List;

/**
 * V4.4新功能演示类
 * 
 * 演示CardCodec和TablePositionConfig的使用
 * 
 * @author PokerMind Team
 * @version V4.4
 */
public class V44FeatureDemo {
    
    public static void main(String[] args) {
        System.out.println("╔════════════════════════════════════════════════════════════╗");
        System.out.println("║         PokerMind V4.4 新功能演示                          ║");
        System.out.println("╚════════════════════════════════════════════════════════════╝");
        System.out.println();
        
        // 演示1: 牌面编码转换
        demoCardCodec();
        
        System.out.println();
        System.out.println("─".repeat(60));
        System.out.println();
        
        // 演示2: 座位配置工具
        demoTablePositionConfig();
        
        System.out.println();
        System.out.println("╔════════════════════════════════════════════════════════════╗");
        System.out.println("║         演示完成！                                          ║");
        System.out.println("╚════════════════════════════════════════════════════════════╝");
    }
    
    /**
     * 演示CardCodec - 牌面编码转换
     */
    private static void demoCardCodec() {
        System.out.println("【演示1】牌面编码转换 (CardCodec)");
        System.out.println("═".repeat(60));
        System.out.println();
        
        // 1. 单个转换
        System.out.println("1️⃣  单个转换");
        System.out.println("   数字 → 标准格式:");
        System.out.println("   0  → " + CardCodec.encodeToStandard(0));   // Ad
        System.out.println("   13 → " + CardCodec.encodeToStandard(13));  // Ac
        System.out.println("   26 → " + CardCodec.encodeToStandard(26));  // Ah
        System.out.println("   39 → " + CardCodec.encodeToStandard(39));  // As
        System.out.println("   51 → " + CardCodec.encodeToStandard(51));  // Ks
        System.out.println();
        
        System.out.println("   标准格式 → 数字:");
        System.out.println("   Ad → " + CardCodec.decodeFromStandard("Ad"));  // 0
        System.out.println("   Ah → " + CardCodec.decodeFromStandard("Ah"));  // 26
        System.out.println("   Ks → " + CardCodec.decodeFromStandard("Ks"));  // 51
        System.out.println();
        
        // 2. 批量转换
        System.out.println("2️⃣  批量转换");
        int[] holeCodes = {26, 51};  // 红桃A, 黑桃K
        String[] holeCards = CardCodec.encodeToStandard(holeCodes);
        System.out.println("   手牌编码: " + Arrays.toString(holeCodes));
        System.out.println("   转换后:   " + Arrays.toString(holeCards));
        System.out.println();
        
        int[] boardCodes = {0, 13, 26, 39};  // 四个A
        String[] boardCards = CardCodec.encodeToStandard(boardCodes);
        System.out.println("   公共牌编码: " + Arrays.toString(boardCodes));
        System.out.println("   转换后:     " + Arrays.toString(boardCards));
        System.out.println();
        
        // 3. 验证
        System.out.println("3️⃣  验证功能");
        System.out.println("   CardCodec.isValidCard(\"Ah\") = " + CardCodec.isValidCard("Ah"));
        System.out.println("   CardCodec.isValidCard(\"XX\") = " + CardCodec.isValidCard("XX"));
        System.out.println("   CardCodec.isValidCode(26)    = " + CardCodec.isValidCode(26));
        System.out.println("   CardCodec.isValidCode(52)    = " + CardCodec.isValidCode(52));
        System.out.println();
        
        // 4. 花色和点数
        System.out.println("4️⃣  花色和点数获取");
        String card = "Ah";
        System.out.println("   牌面: " + card);
        System.out.println("   点数: " + CardCodec.getRank(card));
        System.out.println("   花色: " + CardCodec.getSuit(card));
        System.out.println("   花色(中文): " + CardCodec.getSuitNameZh(card));
        System.out.println("   花色(英文): " + CardCodec.getSuitNameEn(card));
        System.out.println("   完整描述: " + CardCodec.getCardDescriptionZh(card));
        System.out.println();
        
        // 5. 编码规则说明
        System.out.println("5️⃣  编码规则");
        System.out.println("   方片(Diamonds): 0-12   →  Ad, 2d, ..., Td, Jd, Qd, Kd");
        System.out.println("   梅花(Clubs):    13-25  →  Ac, 2c, ..., Tc, Jc, Qc, Kc");
        System.out.println("   红桃(Hearts):   26-38  →  Ah, 2h, ..., Th, Jh, Qh, Kh");
        System.out.println("   黑桃(Spades):   39-51  →  As, 2s, ..., Ts, Js, Qs, Ks");
        System.out.println();
        
        // 6. 四个A的编码快速查询
        System.out.println("6️⃣  常用牌编码速查");
        System.out.println("   四个A: Ad(0), Ac(13), Ah(26), As(39)");
        System.out.println("   四个K: Kd(12), Kc(25), Kh(38), Ks(51)");
    }
    
    /**
     * 演示TablePositionConfig - 座位配置工具
     */
    private static void demoTablePositionConfig() {
        System.out.println("【演示2】座位配置工具 (TablePositionConfig)");
        System.out.println("═".repeat(60));
        System.out.println();
        
        // 1. 不同人数桌的标准配置
        System.out.println("1️⃣  不同人数桌的标准配置");
        for (int playerCount : new int[]{2, 3, 6, 9}) {
            List<String> positions = TablePositionConfig.getPositionsForPlayerCount(playerCount);
            System.out.printf("   %d人桌: %s%n", playerCount, positions);
        }
        System.out.println();
        
        // 2. 6人桌详细示例
        System.out.println("2️⃣  6人桌配置详解（最常见）");
        List<String> positions6 = TablePositionConfig.TABLE_6;
        System.out.println("   标准位置: " + positions6);
        System.out.println();
        
        // 行动顺序
        System.out.println("   翻前行动顺序:");
        List<String> preFlopOrder = TablePositionConfig.getPreFlopActionOrder(positions6);
        System.out.println("   " + String.join(" → ", preFlopOrder));
        System.out.println();
        
        System.out.println("   翻后行动顺序:");
        List<String> postFlopOrder = TablePositionConfig.getPostFlopActionOrder(positions6);
        System.out.println("   " + String.join(" → ", postFlopOrder));
        System.out.println();
        
        // 3. 9人满桌配置
        System.out.println("3️⃣  9人满桌配置（Full Ring）");
        List<String> positions9 = TablePositionConfig.FULL_RING_9;
        System.out.println("   标准位置: " + positions9);
        System.out.println();
        
        System.out.println("   位置-座位号映射:");
        for (String position : positions9) {
            int seatNumber = TablePositionConfig.getSeatNumberFor9Player(position);
            System.out.printf("   %6s → 座位%d%n", position, seatNumber);
        }
        System.out.println();
        
        // 4. 位置验证
        System.out.println("4️⃣  位置验证");
        System.out.println("   isValidPosition(\"BTN\") = " + 
            TablePositionConfig.isValidPosition("BTN"));
        System.out.println("   isValidPosition(\"XXX\") = " + 
            TablePositionConfig.isValidPosition("XXX"));
        System.out.println();
        
        // 5. 位置分类
        System.out.println("5️⃣  位置分类");
        String[] positionsToTest = {"UTG", "LJ", "CO", "SB"};
        for (String position : positionsToTest) {
            PositionCategory category = TablePositionConfig.getPositionCategory(position);
            System.out.printf("   %6s: %s (%s)%n", 
                position, 
                category.getNameZh(), 
                category.getNameEn());
        }
        System.out.println();
        
        // 6. 位置名称
        System.out.println("6️⃣  位置名称（中英文）");
        String[] positionsForName = {"BTN", "SB", "BB", "UTG", "LJ", "HJ", "CO"};
        for (String position : positionsForName) {
            String nameZh = TablePositionConfig.getPositionNameZh(position);
            String nameEn = TablePositionConfig.getPositionNameEn(position);
            System.out.printf("   %6s: %s / %s%n", position, nameZh, nameEn);
        }
        System.out.println();
        
        // 7. 配置验证
        System.out.println("7️⃣  配置验证");
        List<String> testConfig = Arrays.asList("BTN", "SB", "BB", "UTG", "HJ", "CO");
        boolean isStandard = TablePositionConfig.isStandardConfig(testConfig, 6);
        System.out.println("   配置: " + testConfig);
        System.out.println("   是否为6人桌标准配置: " + isStandard);
        System.out.println();
        
        // 8. 支持范围
        System.out.println("8️⃣  支持范围");
        System.out.println("   最小玩家数: " + TablePositionConfig.getMinPlayers());
        System.out.println("   最大玩家数: " + TablePositionConfig.getMaxPlayers());
        System.out.println("   支持7人桌: " + TablePositionConfig.isSupportedPlayerCount(7));
        System.out.println("   支持10人桌: " + TablePositionConfig.isSupportedPlayerCount(10));
    }
}

